<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-01-06 13:47:30
 * @LastEditors: 卡卡 1071780426@qq.com
 * @LastEditTime: 2023-10-27 11:34:19
 * @FilePath: \mould\src\views\pages\Supervision\deliverability.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" id="buttonId" style="width: 100%">
          <!-- <el-date-picker
            :default-time="['00:00:00', '23:59:59']"
            clearable
            @change="selectTime"
            v-model="value2"
            :picker-options="pickerOptions"
            size="medium"
            style="width: 25%"
            type="datetimerange"
            range-separator="-"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker> -->

          <el-date-picker
            v-model="value1"
            clearable
            @change="selectTime"
            type="date"
            size="medium"
            style="width: 25%"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
          <el-time-picker
            is-range
            v-model="hms"
            :default-time="['00:00:00', '23:59:59']"
            clearable
            @change="selectTime1"
            size="medium"
            style="width: 25%"
            value-format="HH:mm:ss"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          >
          </el-time-picker>

          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.stationId"
            placeholder="所有拌和站"
            @change="selectBhz"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.machineId"
            placeholder="所有拌和机"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>

      <!-- 表格 -->
      <div class="" style="width: 100%; height: 100%">
        <myCharts
          :aggregateData="aggregateData"
          v-loading="chartsLoading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.3)"
          :checkType="checkType"
          :time1="this.getList.startDates"
          :time2="this.getList.endDates"
          :commonData="tableData"
          @clickLegend="clickLegend"
        >
        </myCharts>
      </div>
      <div class="text_table"></div>
    </div>
  </div>
</template>
  
<script>
// const cityOptions = ['上海', '北京', '广州', '深圳'];
import tree from "@/components/public/el-trees"; //左侧机构树
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
// import selects from "@/components/public/el-select.vue"
import myCharts from "@/components/public/timePeriodCharts";

// import formJs from './regexDetail.js'//新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  getCensusList2, //查询-产能分析列表页
  getStationmachineList, //拌合站列表
  getStationmachineByfMachineid,
  getMachineListByStationId, //拌合机
} from "@/api/request.js";

export default {
  name: "timePeriod",
  data() {
    return {
      name: "timePeriod", //按钮配置页面代号
      yj_view: null, //查看按钮是否显示
      formData: {}, //新增编辑向后台传递对象

      //限制时间范围选择(两天)
      pickerMinDate: "",
      // pickerOptions: {
      //     //onPick当type="datetimerange"时有效
      //     onPick: ({ maxDate, minDate }) => {
      //         this.pickerMinDate = minDate.getTime()
      //         if (maxDate) {
      //             this.pickerMinDate = ''
      //         }
      //     },
      //     disabledDate: (time) => {
      //         if (this.pickerMinDate != '') {
      //             // let tow = 1 * 24 * 3600 * 1000 //重点是在这里计算相差几天
      //             let minTime = this.pickerMinDate
      //             let maxTime = this.pickerMinDate
      //             return time.getTime() < minTime || time.getTime() > maxTime

      //         }
      //     }
      // },

      bhjDataList: [], //拌合机
      bhzDataList: [], //拌合站
      value1: "",
      hms: "", //时分秒
      startTime: new Date(2016, 9, 10, 0, 0),
      endTime: new Date(2016, 9, 10, 0, 0),

      // 列表配置项
      table_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",
        dialogHeight: "",
        thead: [
          {
            label: "材料类型",
            prop: "type",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "水",
            prop: "F_WaterActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "水泥1",
            prop: "F_Cement1ActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "水泥2",
            prop: "F_Cement2ActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "骨料1",
            prop: "F_Aggregate1ActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "骨料2",
            prop: "F_Aggregate2ActualValue",
            minWidth: "100px",
            align: "center",
          },
          //
          {
            label: "骨料3",
            prop: "F_Aggregate3ActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "骨料4",
            prop: "F_Aggregate4ActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "骨料5",
            prop: "F_Aggregate5ActualValue",
            minWidth: "100px",
            align: "center",
          },

          {
            label: "粉煤灰",
            prop: "F_OreActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "矿粉",
            prop: "F_FlyashActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "外加剂1",
            prop: "F_Admixture1ActualValue",
            minWidth: "100px",
            align: "center",
          },
          {
            label: "外加剂2",
            prop: "F_Admixture2ActualValue",
            minWidth: "100px",
            align: "center",
          },
        ],
        isCheckBox: false,
        isIndex: false,
        isOperation: true,
        // 表格操作列
      },
      tableData: [], //表格列表数据列表

      highlightBd: true, //左侧机构树停留背景色

      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",

      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        companyId: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        machineId: "", // 拌和机编号
        enCode: "",
        stationId: "",
      },
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据

      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      checkType: {
        全选: false,
        全不选: false,
        水: false,
        水泥1: true,
        水泥2: false,
        骨料1: true,
        骨料2: true,
        骨料3: true,
        骨料4: true,
        骨料5: true,
        矿粉: false,
        粉煤灰: true,
        外加剂1: true,
        外加剂2: true,
      },
      chartsLoading: true,
      aggregateData: [],
    };
  },
  components: {
    tree, //左侧组织机构数

    elBreadcrumb, //面包屑

    myCharts,
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_userInfo"));
    if (JSON.parse(sessionStorage.getItem("GxEmbedded_getLists"))) {
      var data = JSON.parse(sessionStorage.getItem("GxEmbedded_getLists"));
      this.getList.machineId = data.machineId; // 拌和机编号
      this.getList.stationId = data.stationId;
      this.getbhjDataMethods(data.stationId);
    }
    if (JSON.parse(sessionStorage.getItem("GxEmbedded_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("GxEmbedded_treeCheck"));
      this.checkData = [id.fCompanyid];
    }

    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },

  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("GxEmbedded_ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_view = true;
      }
    },

    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "1", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("GxEmbedded_treeCheck")
              ).fShortname;
              this.getList.companyId = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
              this.checkData[0] = this.treeData[0].fCompanyid;
            }
            this.mixingPlantList(0, this.getList);

            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.companyId = data.fCompanyid;
      this.mixingPlantList(0, this.getList);
      //   var time = new Date();
      //   const y = time.getFullYear();
      //   const m = (time.getMonth() + 1 + "").padStart(2, "0");
      //   const d = (time.getDate() + "").padStart(2, "0");
      //   const hh = (time.getHours() + "").padStart(2, "0");
      //   const mm = (time.getMinutes() + "").padStart(2, "0");
      //   const ss = (time.getSeconds() + "").padStart(2, "0");

      //   this.getList.startDates = `${y}-${m}-${d}` + " " + "00:00:00"; // 开始时间
      //   this.getList.endDates = `${y}-${m}-${d} ${hh}:${mm}:${ss}`; // 截至时间

      this.getList.machineId = ""; // 拌和机编号
      this.getList.stationId = "";
      //   this.value1 = `${y}-${m}-${d}`;
      // this.value2 = [`${y}-${m}-${d}` + " " + '00:00:00', `${y}-${m}-${d} ${hh}:${mm}:${ss}`]
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      this.chartsLoading = true;
      var id;
      if (data.fCompanyid != "") {
        id = data.fCompanyid;
      } else {
        id = data.fprojectid;
      }
      var getList={
        companyId: id, // 施工标段id
        startDates: data.startDates, // 开始时间
        endDates: data.endDates, // 截至时间
        machineId: data.machineId, // 拌和机编号
        stationId: data.stationId, // 拌和站编号
        enCode: "",
      }
      if (data.machineId != "") {
        getStationmachineByfMachineid({ machineId: data.machineId }).then(
          (res1) => {
            if (res1.errcode == 0) {
              this.aggregateData = [
                res1.data.yjQmpMsStationmachine.fParm1,
                res1.data.yjQmpMsStationmachine.fParm2,
                res1.data.yjQmpMsStationmachine.fParm3,
                res1.data.yjQmpMsStationmachine.fParm4,
                res1.data.yjQmpMsStationmachine.fParm5,
              ];
              getCensusList2(getList)
                .then((res) => {
                  if (res.errcode == 0) {
                    var that = this;
                    that.listLoading = false;
                    this.chartsLoading = false;

                    that.tableData = {
                      data: res.data.censusList2,
                      type: this.checkType,
                    };
                  } else {
                    this.$message.error(res.msg);
                    this.chartsLoading = false;

                    return false;
                  }
                })
                .catch((error) => {
                  console.log(error);
                });
            }
          }
        );
      } else {
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_checkData"))) {
          // this.checkType = JSON.parse(sessionStorage.getItem("GxEmbedded_checkData"));
          var checkObj = JSON.parse(sessionStorage.getItem("GxEmbedded_checkData"));
          if (
            checkObj.外加剂1 == true &&
            checkObj.外加剂2 == true &&
            checkObj.水 == true &&
            checkObj.水泥1 == true &&
            checkObj.水泥2 == true &&
            checkObj.矿粉 == true &&
            checkObj.粉煤灰 == true &&
            checkObj.骨料1 == true &&
            checkObj.骨料2 == true &&
            checkObj.骨料3 == true &&
            checkObj.骨料4 == true &&
            checkObj.骨料5 == true
          ) {
            checkObj.全选 = true;
            checkObj.全不选 = false;
          } else if (
            checkObj.外加剂1 == false &&
            checkObj.外加剂2 == false &&
            checkObj.水 == false &&
            checkObj.水泥1 == false &&
            checkObj.水泥2 == false &&
            checkObj.矿粉 == false &&
            checkObj.粉煤灰 == false &&
            checkObj.骨料1 == false &&
            checkObj.骨料2 == false &&
            checkObj.骨料3 == false &&
            checkObj.骨料4 == false &&
            checkObj.骨料5 == false
          ) {
            checkObj.全选 = false;
            checkObj.全不选 = true;
          } else {
            checkObj.全选 = false;
            checkObj.全不选 = false;
          }
          this.checkType = checkObj;
        } else {
          this.checkType = {
            全选: false,
            全不选: false,
            水: false,
            水泥1: true,
            水泥2: false,
            骨料1: true,
            骨料2: true,
            骨料3: true,
            骨料4: true,
            骨料5: true,
            矿粉: false,
            粉煤灰: true,
            外加剂1: true,
            外加剂2: true,
          };
        }
        this.aggregateData = ["骨料1", "骨料2", "骨料3", "骨料4", "骨料5"];
        getCensusList2(getList)
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.listLoading = false;
              this.chartsLoading = false;

              that.tableData = {
                data: res.data.censusList2,
                type: this.checkType,
              };
            } else {
              this.$message.error(res.msg);
              this.chartsLoading = false;

              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
    },

    // 获取拌合站数据
    mixingPlantList(num, datas) {
      // // this.getList.fCompanyid this.checkData[0]
      var data = {
        companyId: datas.companyId, // 施工标段id
        modelType: num, // 类型
        stationType: "1", // 拌合站类型
      };

      // this.bhzDataList = [];
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            // if (num == 1) {
            //   this.bhjDataList = [
            //     {
            //       fItemName: "所有拌和机",
            //       fItemValue: "",
            //     },
            //   ];
            //   arr.map((item) => {
            //     this.bhjDataList.push({
            //       fItemName: item.fMachinename,
            //       fItemValue: item.fMachineid
            //     });
            //   });
            // } else
            // if (num == 0) {
            this.bhzDataList = [
              {
                fItemName: "所有拌和站",
                fItemValue: "",
              },
            ];

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
            // }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 拌合站选择
    selectBhz(e) {
      this.getList.machineId = "";
      this.getbhjDataMethods(e);
      // this.yj_searchForm(this.getList)
    },

    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    clickLegend(e) {
      this.checkType = e;
      window.sessionStorage.setItem("GxEmbedded_checkData", JSON.stringify(e));
    },
    // 时间间隔
    selectTime1(e) {
      this.getList.startDates = this.value1 + " " + e[0]; // 开始时间
      this.getList.endDates = this.value1 + " " + e[1]; // 截至时间

      this.xlsxName =
        this.getList.startDates +
        "至" +
        this.getList.endDates +
        "混凝土拌和站记录数据";

      this.yj_searchForm(this.getList);
    },
    selectTime(e) {
      this.getList.startDates = e + " " + this.hms[0]; // 开始时间
      this.getList.endDates = e + " " + this.hms[1]; // 截至时间
      this.xlsxName =
        this.getList.startDates +
        "至" +
        this.getList.endDates +
        "混凝土拌和站记录数据";

      this.yj_searchForm(this.getList);
    },
    getDate() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      const hh = (time.getHours() + "").padStart(2, "0");
      const mm = (time.getMinutes() + "").padStart(2, "0");
      const ss = (time.getSeconds() + "").padStart(2, "0");

      this.getList.startDates = `${y}-${m}-${d}` + " " + "00:00:00"; // 开始时间
      this.getList.endDates = `${y}-${m}-${d} ${hh}:${mm}:${ss}`; // 截至时间
      this.value1 = `${y}-${m}-${d}`;
      this.hms = ["00:00:00", "23:59:59"];
      this.xlsxName =
        `${y}-${m}-01` + "至" + `${y}-${m}-${d}` + "混凝土拌和站记录数据";
      if (JSON.parse(sessionStorage.getItem("GxEmbedded_getLists"))) {
        var data = JSON.parse(sessionStorage.getItem("GxEmbedded_getLists"));
        this.getList.machineId = data.machineId; // 拌和机编号
      } else {
        this.getList.machineId = ""; // 拌和机编号
      }
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
  
<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.materialCharts {
  height: calc(100% - 110px);
  width: 100%;
}

#buttonId /deep/ .el-time-panel__footer {
  height: auto;
}

/* .selectcheckbox {
    margin-left: 15px;
    margin-top: -5px;
    height: 35px;
} */
</style>